import 'package:enterprise_v6_app/app/core/core.dart';

///自定义实现Radio，利用图片实现更换选中和不选择的状态
class RadioOption<T> extends StatelessWidget {

  const RadioOption({required this.value, required this.groupValue, required this.text, required this.selectImage, required this.unSelectImage, required this.onChanged, super.key,
  });
  final T value;
  final T? groupValue;
  final String selectImage;
  final String unSelectImage;
  final String text;
  final ValueChanged<T?> onChanged;

  Widget _buildLabel() {
    final bool isSelected = value == groupValue;
    return SizedBox(
      width: 16.w,
      height: 16.w,
      child: SvgPicture.asset(isSelected ? selectImage : unSelectImage),
    );
  }

  Widget _buildText() {
    return Text(
      text,
      style: TextStyle(color: const Color(0xFF262F38), fontSize: 14.sp),
    );
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => onChanged(value),
      child: Row(
        children: [
          _buildLabel(),
          AppGaps.hGap8,
          _buildText(),
        ],
      ),
    );
  }
}
